<template>
	<view>
		<cu-custom bgColor="bg-maincolor" :isBack="true">
			<block slot="content">
				学校申请
			</block>
		</cu-custom>
		<view>
			<view class="apply_boxone">
				<view>学校资料</view>
			</view>
			<view class="apply_box flex">
				<view class="con_text">学校名称</view>
				<input class="con_infom" placeholder="请输入学校名称" v-model="school_name"/>
			</view>
			<view class="apply_box flex">
				<view class="con_text">联系人</view>
				<input class="con_infom" placeholder="请输入联系人姓名" v-model="contacts"/>
			</view>
			<view class="apply_box flex">
				<view class="con_text">电话</view>
				<input class="con_infom" placeholder="请输入联系人电话" v-model="phone"/>
			</view>
			<view class="apply_box flex">
				<view class="con_text">地址</view>
				<input class="con_infom" placeholder="请输入学校地址" v-model="address"/>
			</view>
			<view class="apply_box flex" style="border-bottom-width:0">
				<view class="con_text">校长姓名</view>
				<input class="con_infom" placeholder="请输入校长姓名" v-model="principal"/>
			</view>
		</view>
		<view class="cu-bar tabbar bg-white foot" v-if="applist==null">
			<button class="cancel_but">取消</button>
			<button class="submit_but" @tap="submit()">提交</button>	
		</view>
		<view class="time" v-if="applist">
			正在申请中，请耐心等待!
		</view>
	</view>
</template>

<script>
	const {appLogin,httpGet,httpPost} = require("@/utils/common.js")
	export default {
		data() {
			return {
				school_name:'',
				logo:'',
				contacts:'',
				phone:'',
				address:'',
				principal:'',
				applist:[]
			}
		},
		onLoad() {
			appLogin((user_info)=>{
				console.log(user_info)
				this.try()
			})
		},
		methods: {
			submit(){
				if(!this.school_name){
					uni.showToast({
						title:'请输入学校姓名',
						icon:'none',
						duration: 2000
					});
					return;
				}
				if(!this.contacts){
					uni.showToast({
						title:'请输入联系姓名！',
						icon:'none',
						duration: 2000
					});
					return;
				}
				if(!this.phone){
					uni.showToast({
						title:'请输入联系电话！',
						icon:'none',
						duration: 2000
					});
					return;
				}
				if(!this.address){
					uni.showToast({
						title:'请输入地址！',
						icon:'none',
						duration: 2000
					});
					return;
				}
				if(!this.principal){
					uni.showToast({
						title:'请输入校长姓名！',
						icon:'none',
						duration: 2000
					});
					return;
				}
				httpPost({
					url:'/api/school/apply',
					data:{
						school_name:this.school_name,
						logo:this.logo,
						contacts:this.contacts,
						phone:this.phone,
						address:this.address,
						principal:this.principal
					}
				}).then(res => {
					console.log(res)
					return uni.showToast({
						title:'已申请',
						icon:'none',
						duration: 2000,
					});
					this.try()
				})
			},
			try(){
				httpGet({
					url:'/api/school/apply_info',
				}).then(res => {
					console.log(res)
					this.applist = res.result
					if(res.result){
						this.applist = res.result
						this.school_name = res.result.school_name,
						this.contacts = res.result.contacts,
						this.phone = res.result.phone,
						this.address = res.result.address,
						this.principal = res.result.principal
					}
				})
			}
		}
	}
</script>

<style>
	
	.apply_boxone{
		height: 90rpx;
		line-height: 90rpx;
		background-color: #efefef;
		font-size: 30rpx;
		padding-left: 38rpx;
		color: #333333;
	}
	
	.apply_box{
		height: 90rpx;
		line-height: 90rpx;
		padding-left: 38rpx;
		background-color: #FFFFFF;
		border-width: 2rpx;
		border-bottom-style: solid;
		border-color: #e6e6e6;
	}
	
	.con_text{
		color: #989898;
		font-size: 30rpx;
	}
	
	.con_infom{
		position: absolute;
		right: 35rpx;
		color: #333333;
		font-size: 30rpx;
		text-align: right;
		line-height: 90rpx;
		height: 90rpx;
		width: 750rpx;
	}
	
	.cancel_but{
		border-radius: 90rpx;
		border-width: 1rpx;
		border-style: solid;
		border-color: #3b73f6;
		text-align: center;
		height: 80rpx;
		width: 335rpx;
		line-height: 80rpx;
		color: #3b73f6;
		font-size: 30rpx;
	}
	
	.submit_but{
		border-radius: 90rpx;
		border-width: 1rpx;
		border-style: solid;
		background-color: #3b73f6;
		text-align: center;
		height: 80rpx;
		width: 335rpx;
		line-height: 80rpx;
		color: #FFFFFF;
		font-size: 30rpx;
	}
	
	.time{
		text-align: center;
		position: absolute;
		bottom: 0;
		height: 120rpx;
		background-color: #FFFFFF;
		width: 100%;
		line-height: 120rpx;
		font-size: 30rpx;
		color: #333333;
		border-top-width: 2rpx;
		border-top-color: #e6e6e6;
		border-top-style: solid;
	}
</style>
